package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.SubmittedWorkEntity;
import com.efast.dmom.mes.service.SubmittedWorkService;

@Controller
@RequestMapping("/submittedWork")
public class SubmittedWorkController {
	
	@Autowired
	private SubmittedWorkService submittedWorkService;
	
	//报工
	@RequestMapping(value = "/submittedWork")
	public @ResponseBody ResultBean submittedWork(@RequestBody SubmittedWorkEntity submittedWorkEntity) {
		ResultBean resultBean = new ResultBean();
		try {
			if (submittedWorkEntity.getSubmittedWorkType() == 1) {
				resultBean = submittedWorkService.submitOutSource(submittedWorkEntity);
			} else {
				resultBean = submittedWorkService.submittedWork(submittedWorkEntity);
			}
			
		} catch (RuntimeException e) {
			String message = e.getMessage();
			resultBean.setSuccess(false);
			resultBean.setMessage(message);
			return resultBean;
		}
		
		
		return resultBean;
	}

}
